import cv2 as cv


def main():
    img = cv.imread('../data/atri.jpg', 0)
    template = cv.imread('../data/clock.jpg', 0)
    w, h = template.shape[::-1]
    methods = [cv.TM_CCOEFF, cv.TM_CCOEFF_NORMED, cv.TM_CCORR, cv.TM_CCORR_NORMED, cv.TM_SQDIFF, cv.TM_SQDIFF_NORMED]

    for method in methods:
        draw_img = img.copy()
        res = cv.matchTemplate(img, template, method)
        min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
        top_left = min_loc if method in [cv.TM_SQDIFF, cv.TM_SQDIFF_NORMED] else max_loc
        bottom_right = (top_left[0] + w, top_left[1] + h)
        cv.rectangle(draw_img, top_left, bottom_right, 255, 2)
        cv.normalize(res, res, 0, 1, cv.NORM_MINMAX)
        cv.imshow("matchRes", res)
        cv.imshow("imgForDraw", draw_img)
        cv.waitKey(0)

    cv.destroyAllWindows()


if __name__ == "__main__":
    main()
